package com.jming.jike.controller.backend;

import com.jming.jike.common.PageResult;
import com.jming.jike.common.ResponseResult;
import com.jming.jike.common.ValidatorGroup.Insert;
import com.jming.jike.common.ValidatorGroup.Query;
import com.jming.jike.common.ValidatorGroup.Update;
import com.jming.jike.dto.backend.CategoryDTO;
import com.jming.jike.service.backend.CategoryService;
import com.jming.jike.vo.backend.CategoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author jinming.zhang
 * @version 0.0.1
 * @date 2022/04/14
 */
@RestController
@RequestMapping("/category")
@Api(tags = "菜品分类相关接口", value = "/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @PostMapping("/insert")
    @ApiOperation(value = "添加菜品分类", notes = "添加菜品分类", produces = "application/json", httpMethod = "POST")
    public ResponseResult<Boolean> insert(@RequestBody @Validated(Insert.class) CategoryDTO categoryDTO) {

        return ResponseResult.success(categoryService.insert(categoryDTO));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改菜品分类", notes = "修改菜品分类", produces = "application/json", httpMethod = "PUT")
    public ResponseResult<Boolean> update(@RequestBody @Validated(Update.class) CategoryDTO categoryDTO) {

        return ResponseResult.success(categoryService.update(categoryDTO));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除菜品分类", notes = "删除菜品分类", produces = "application/json", httpMethod = "DELETE")
    public ResponseResult<Boolean> delete(@PathVariable("id") Long id) {

        return ResponseResult.success(categoryService.delete(id));
    }

    @PostMapping("/pageQuery")
    @ApiOperation(value = "分页查询分类列表", notes = "分页查询分类列表", produces = "application/json", httpMethod = "POST")
    public ResponseResult<PageResult<CategoryVO>> pageQuery(@RequestBody @Validated(Query.class) CategoryDTO categoryDTO) {

        return ResponseResult.success(categoryService.pageQuery(categoryDTO));
    }

    @GetMapping("/queryDetail/{id}")
    @ApiOperation(value = "根据id查询分类详情信息", notes = "根据id查询分类详情信息", produces = "application/json", httpMethod = "GET")
    public ResponseResult<CategoryVO> queryDetail(@PathVariable("id") Long id) {

        return ResponseResult.success(categoryService.queryDetail(id));
    }

    @GetMapping("/queryCategoryListByType/{type}")
    @ApiOperation(value = "根据分类类型查询分类列表", notes = "根据分类类型查询分类列表", produces = "application/json", httpMethod = "GET")
    public ResponseResult<List<CategoryVO>> queryCategoryListByType(@PathVariable("type") Integer type) {

        return ResponseResult.success(categoryService.queryCategoryListByType(type));
    }

}
